﻿using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;
using System.Linq;

using CE.User;
using CE.Global;
using CE.Database;
using CE.CarInsurance;

public partial class reports_ViewSalesSummary : System.Web.UI.Page
{
    private DateTime dateTimeNow = CE.Global.General.GetUTCDateTime();

    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/SiteUserSecureLogin.aspx");
        }

        if (!IsPostBack)
        {
            lblError.Text = "";
            lblContent.Text = "";
            ddlDay1.Visible = true;
            lblFromDate.Text = Resources.General.Date + " : ";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
            ddlYear1.Items.Clear();
            ddlYear2.Items.Clear();

            int _cryr = dateTimeNow.Year;
            int _styr = 2010;
            for (int _year = _cryr; _year >= _styr; _year--)
            {
                ddlYear1.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
                ddlYear2.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
            }

            ddlDay1.Text = dateTimeNow.Day.ToString("00");
            ddlMonth1.Text = dateTimeNow.Month.ToString("00");
            ddlYear1.Text = dateTimeNow.Year.ToString("0000");
            ddlDay2.Text = dateTimeNow.Day.ToString("00");
            ddlMonth2.Text = dateTimeNow.Month.ToString("00");
            ddlYear2.Text = dateTimeNow.Year.ToString("0000");
            ddlReportType_SelectedIndexChanged(null, null);
        }

        if (Session[General.UserRole] != null && Session[General.UserRole].ToString() == "100")
        {
            ibtSubmit.Visible = false;
            ddlReportType.Enabled = false;
            grvSalesSummary.Visible = false;
            ddlDay1.Enabled = false;
            ddlMonth1.Enabled = false;
            ddlYear1.Enabled = false;
            lblError.Text = Resources.CarInsurance.YourAreNotAuthorizedToViewPage;
        }
    }

    protected void ibtSubmit_Click(object sender, EventArgs e)
    {
        lblError.Text = "";
        txtReportType.Text = ddlReportType.Text;
        txtAgentId.Text = Session[CE.Global.General.UserId].ToString();
        LoadGrid();
    }

    protected void btnDownLoad_Click(object sender, EventArgs e)
    {
        GenerateExcel();
    }

    protected void ddlReportType_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblError.Text = "";
        ddlDay1.Text = dateTimeNow.Day.ToString("00");
        ddlDay2.Text = dateTimeNow.Day.ToString("00");
        ddlMonth1.Text = dateTimeNow.Month.ToString("00");
        ddlMonth2.Text = dateTimeNow.Month.ToString("00");
        ddlYear1.Text = dateTimeNow.Year.ToString("0000");
        ddlYear2.Text = dateTimeNow.Year.ToString("0000");
        if (Convert.ToInt16(ddlReportType.Text) == 0)
        {
            ddlDay1.Visible = false;
            lblFromDate.Text = Resources.General.Date + " : ";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 1)
        {
            ddlDay1.Visible = true;
            lblFromDate.Text = Resources.General.Date + " : ";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 2)
        {
            lblFromDate.Text = " " + Resources.General.FromDate + " : ";
            lblToDate.Text = " " + Resources.General.ToDate + " : ";
            lblToDate.Visible = true;
            ddlDay2.Visible = true;
            ddlMonth2.Visible = true;
            ddlYear2.Visible = true;
            ddlDay1.Visible = true;
        }
    }

    protected void grvSalesSummary_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[7].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[8].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[9].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[10].Attributes.CssStyle.Add("text-align", "right");
        }
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             e.Row.Cells[7].Attributes.CssStyle.Add("text-align", "right");
             e.Row.Cells[8].Attributes.CssStyle.Add("text-align", "right");
             e.Row.Cells[9].Attributes.CssStyle.Add("text-align", "right");
             e.Row.Cells[10].Attributes.CssStyle.Add("text-align", "right");
         }
    }

    public bool ValidDate(Int32 Year, Int32 Month, Int32 Day)
    {
        bool _isValid = true;
        int daysInMonth = 0;
        string leap, monthValid, dayValid, yearValid;
        if (Year >= 0000)
        {
            yearValid = "yes";
        }
        else
        {
            yearValid = "no";
        }
        if (Year % 400 == 0)
        {
            leap = "yes";
        }
        else if (Year % 100 == 0)
        {
            leap = "no";
        }
        else if (Year % 4 == 0)
        {
            leap = "yes";
        }
        else
        {
            leap = "no";
        }

        switch (Month)
        {
            case 1: daysInMonth = 31;
                break;
            case 3: daysInMonth = 31;
                break;
            case 4: daysInMonth = 30;
                break;
            case 5: daysInMonth = 31;
                break;
            case 6: daysInMonth = 30;
                break;
            case 7: daysInMonth = 31;
                break;
            case 8: daysInMonth = 31;
                break;
            case 9: daysInMonth = 30;
                break;
            case 10: daysInMonth = 31;
                break;
            case 11: daysInMonth = 30;
                break;
            case 12: daysInMonth = 31;
                break;
        }

        if (Month >= 1 && Month <= 12)
        {
            monthValid = "yes";
        }
        else
        {
            monthValid = "no";
        }
        if (Month == 2)
        {
            if (leap == "no")
            {
                daysInMonth = 28;
            }
            else if (leap == "yes")
            {
                daysInMonth = 29;
            }
        }

        if (1 <= Day && Day <= daysInMonth)
        {
            dayValid = "yes";
        }

        else
        {
            dayValid = "no";
        }

        if ((dayValid == "yes") && (monthValid == "yes") && (yearValid == "yes"))
        {
            _isValid = true;
        }
        else
        {
            _isValid = false;
        }

        return _isValid;
    }

    public string GetMonth(string month)
    {
        string result = "";
        if (month == "01")
        {
            result = " Jan ";
        }
        else if (month == "02")
        {
            result = " Feb ";
        }
        else if (month == "03")
        {
            result = " Mar ";
        }
        else if (month == "04")
        {
            result = " Apr ";
        }
        else if (month == "05")
        {
            result = " May ";
        }
        else if (month == "06")
        {
            result = " Jun ";
        }
        else if (month == "07")
        {
            result = " Jul ";
        }
        else if (month == "08")
        {
            result = " Aug ";
        }
        else if (month == "09")
        {
            result = " Sep ";
        }
        else if (month == "10")
        {
            result = " Oct ";
        }
        else if (month == "11")
        {
            result = " Nov ";
        }
        else if (month == "12")
        {
            result = " Dec ";
        }
        return result;
    }

    public bool Validatioin()
    {
        lblError.Text = "";
        bool _isValid = true;
        DateTime _fromDate, _toDate;
        if (Convert.ToInt16(ddlReportType.Text) == 1)
        {
            if (ddlDay1.SelectedIndex >= 0)
            {
                if (ValidDate(Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlDay1.Text)))
                {
                    _fromDate = Convert.ToDateTime(Convert.ToInt32(ddlYear1.Text) + "/" + Convert.ToInt32(ddlMonth1.Text) + "/" + Convert.ToInt32(ddlDay1.Text));
                    if (_fromDate > dateTimeNow)
                    {
                        _isValid = false;
                        lblError.Text = Resources.General.ErrDatelessorequalToday;
                    }
                }
                else
                {
                    _isValid = false;
                    lblError.Text = Resources.General.ErrSelectValidDate;
                }
            }
            else
            {
                _isValid = false;
                lblError.Text = Resources.General.ErrSelectDate;
            }
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 2)
        {
            if (ddlDay1.SelectedIndex >= 0 && ddlDay2.SelectedIndex >= 0)
            {
                if (ValidDate(Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlDay1.Text)))
                {
                    _fromDate = Convert.ToDateTime(Convert.ToInt32(ddlYear1.Text) + "/" + Convert.ToInt32(ddlMonth1.Text) + "/" + Convert.ToInt32(ddlDay1.Text));
                    if (ValidDate(Convert.ToInt32(ddlYear2.Text), Convert.ToInt32(ddlMonth2.Text), Convert.ToInt32(ddlDay2.Text)))
                    {
                        _toDate = Convert.ToDateTime(Convert.ToInt32(ddlYear2.Text) + "/" + Convert.ToInt32(ddlMonth2.Text) + "/" + Convert.ToInt32(ddlDay2.Text));
                        if (_fromDate <= dateTimeNow)
                        {
                            if (_fromDate > _toDate)
                            {
                                _isValid = false;
                                lblError.Text = Resources.General.ErrFromdatelessthanTodate;
                            }
                        }
                        else
                        {
                            _isValid = false;
                            lblError.Text = Resources.General.ErrFromdatelessthanToday;
                        }
                    }
                    else
                    {
                        _isValid = false;
                        lblError.Text = Resources.General.ErrSelectValidTodate;
                    }
                }
                else
                {
                    _isValid = false;
                    lblError.Text = Resources.General.ErrSelectValidFromdate;
                }
            }
            else
            {
                _isValid = false;
                lblError.Text = Resources.General.ErrSelectFromandTodate;
            }
        }
        return _isValid;
    }

    public void LoadGrid()
    {
        lblError.Text = "";
        if (Validatioin() == true)
        {
            txtReportDate1.Text = "";
            txtReportDate2.Text = dateTimeNow.Year.ToString("0000") + dateTimeNow.Month.ToString("00") + dateTimeNow.Day.ToString("00");
            txtReportDate1.Text = ddlYear1.Text;
            txtReportDate1.Text += ddlMonth1.Text;
            if (ddlReportType.SelectedIndex > 0)
            {
                if (ddlDay1.SelectedIndex >= 0)
                {
                    txtReportDate1.Text += ddlDay1.Text;
                }
            }
            if (ddlReportType.SelectedIndex == 2)
            {
                txtReportDate2.Text = ddlYear2.Text;
                txtReportDate2.Text += ddlMonth2.Text;
                txtReportDate2.Text += ddlDay2.Text;
            }
            DataSet _dsSummary = new DataSet();
            DataTable _dtSummary = new DataTable();
            Int16 _ReportType = Convert.ToInt16(ddlReportType.Text);
            string _ReportDate1 = txtReportDate1.Text.Trim();
            string _ReportDate2 = txtReportDate2.Text.Trim();
            if (_ReportDate1.Length == 6)
            {
                txtReportDate.Text = _ReportDate1.ToString() + "01";
            }
            else if (_ReportDate1.Length == 8)
            {
                txtReportDate.Text = _ReportDate1.ToString();
            }

            MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
            string _spName = "[sprocCXCRMAgentSalesSummarySelectedList]";
            SortedList _sPara = new SortedList();

            _sPara.Add("@ReportType", _ReportType);
            _sPara.Add("@ReportDate1", _ReportDate1);
            _sPara.Add("@ReportDate2", _ReportDate2);

            _dsSummary = _db.GetDataSet(_spName, _sPara);
            if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
            {
                _dtSummary = _dsSummary.Tables[0];
                grvSalesSummary.DataSource = _dtSummary;
                grvSalesSummary.DataBind();
            }
            else
            {
                grvSalesSummary.DataSource = null;
                grvSalesSummary.DataBind();
                EnablePrintView();
            }
            if (grvSalesSummary.Rows.Count > 0)
            {
                btnDownLoad.Visible = true;
                lblRecordCount.Text = "(" + grvSalesSummary.Rows.Count.ToString() + ") record(s). Date/Time: " + dateTimeNow.ToString("dd-MMM-yyyy hh:mm tt") + "&nbsp;&nbsp;";
            }
            else
            {
                btnDownLoad.Visible = false;
                lblRecordCount.Text = "No record found. Date/Time: " + dateTimeNow.ToString("dd-MMM-yyyy hh:mm tt") + "&nbsp;&nbsp;";
            }
        }
        else
        {
            grvSalesSummary.DataSource = null;
            grvSalesSummary.DataBind();
            EnablePrintView();
        }
    }

    private void EnablePrintView()
    {
        if (grvSalesSummary.Rows.Count > 0)
        {
            btnPrint.Visible = true;
            btnDownLoad.Visible = true;
            lblRecordCount.Text = "(" + grvSalesSummary.Rows.Count.ToString() + ") record(s). Date/Time: " + dateTimeNow.ToString("dd-MMM-yyyy hh:mm tt") + "&nbsp;&nbsp;";
        }
        else
        {
            btnPrint.Visible = false;
            btnDownLoad.Visible = false;
            lblRecordCount.Text = "No record found. Date/Time: " + dateTimeNow.ToString("dd-MMM-yyyy hh:mm tt") + "&nbsp;&nbsp;";
        }
    }

    public void ExportGridView(string fileName, Label lblContent)
    {
        string attachment = "attachment; filename=" + fileName + ".xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        Response.Write(lblContent.Text);
        Response.End();
    }

    public void GenerateExcel()
    {
        string _html = "";
        string _fileName = "AgentSales@" + dateTimeNow.Day.ToString("00") + "-" + dateTimeNow.Month.ToString("00") + "-" + dateTimeNow.Year;
        lblContent.Text = "";
        lblError.Text = "";
        if (Validatioin() == true)
        {
            txtReportDate1.Text = "";
            txtReportDate2.Text = dateTimeNow.Year.ToString("0000") + dateTimeNow.Month.ToString("00") + dateTimeNow.Day.ToString("00");
            txtReportDate1.Text = ddlYear1.Text;
            txtReportDate1.Text += ddlMonth1.Text;
            if (ddlReportType.SelectedIndex > 0)
            {
                if (ddlDay1.SelectedIndex >= 0)
                {
                    txtReportDate1.Text += ddlDay1.Text;
                }
            }
            if (ddlReportType.SelectedIndex == 2)
            {
                txtReportDate2.Text = ddlYear2.Text;
                txtReportDate2.Text += ddlMonth2.Text;
                txtReportDate2.Text += ddlDay2.Text;
            }

            Int32 OnlineCount = 0;
            Int32 OfflineCount = 0;
            Int32 TotalFileCount = 0;
            DataSet _dsSummary = new DataSet();
            DataTable _dtSummary = new DataTable();
            Int16 _ReportType = Convert.ToInt16(ddlReportType.Text);
            string _ReportDate1 = txtReportDate1.Text.Trim();
            string _ReportDate2 = txtReportDate2.Text.Trim();

            MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
            string _spName = "[sprocCXCRMAgentSalesSummarySelectedList]";
            SortedList _sPara = new SortedList();

            _sPara.Add("@ReportType", _ReportType);
            _sPara.Add("@ReportDate1", _ReportDate1);
            _sPara.Add("@ReportDate2", _ReportDate2);

            _dsSummary = _db.GetDataSet(_spName, _sPara);
            if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
            {
                _dtSummary = _dsSummary.Tables[0];
                TotalFileCount += _dtSummary.Rows.Count;
            }
            if (TotalFileCount > 0)
            {
                #region Variable Declaration
                string PaymentType = "";
                string[] QuoteRefNo = new string[TotalFileCount];
                string[] CECarId = new string[TotalFileCount];
                string[] ProviderCompanyId = new string[TotalFileCount];
                string[] OrderDate = new string[TotalFileCount];
                string[] CustomerType = new string[TotalFileCount];
                string[] ApplicationName = new string[TotalFileCount];
                string[] Insurer = new string[TotalFileCount];
                string[] InsuranceType = new string[TotalFileCount];
                string[] InsuranceTypeId = new string[TotalFileCount];
                string[] PolicyStartDate = new string[TotalFileCount];
                string[] PolicyEndDate = new string[TotalFileCount];
                string[] SalesPremium = new string[TotalFileCount];
                string[] GrossPremium = new string[TotalFileCount];
                string[] NetPremium = new string[TotalFileCount];
                string[] Duty = new string[TotalFileCount];
                string[] VAT = new string[TotalFileCount];
                string[] CPolicyStartDate = new string[TotalFileCount];
                string[] CPolicyEndDate = new string[TotalFileCount];
                string[] CNetPremium = new string[TotalFileCount];
                string[] CDuty = new string[TotalFileCount];
                string[] CVAT = new string[TotalFileCount];
                string[] CGrossPremium = new string[TotalFileCount];
                string[] CollectedPremium = new string[TotalFileCount];
                string[] DiscounttoCustomer = new string[TotalFileCount];
                string[] Discount = new string[TotalFileCount];
                string[] Agent = new string[TotalFileCount];
                string[] Remark = new string[TotalFileCount];
                string[] PremiumReceivingDate = new string[TotalFileCount];
                string[] Bank = new string[TotalFileCount];
                string[] MethodofPayment = new string[TotalFileCount];
                string[] BBLBankCharge = new string[TotalFileCount];
                string[] VAT7 = new string[TotalFileCount];
                string[] BBLNetReceived = new string[TotalFileCount];
                string[] IsCTPL = new string[TotalFileCount];
                string[] CTPL = new string[TotalFileCount];
                string[] GarageType = new string[TotalFileCount];

                string[] OICInsurer = new string[10];
                string[] OICVoluntary = new string[10];
                string[] OICCompulsory = new string[10];
                string[] OICTotal = new string[10];

                string[] IntInsurer = new string[10];
                string[] IntVoluntary = new string[10];
                string[] IntCompulsory = new string[10];
                string[] IntTotal = new string[10];

                string[] MktInsurer = new string[10];
                string[] MktVoluntary = new string[10];
                string[] MktCompulsory = new string[10];
                string[] MktTotal = new string[10];

                int int_PayCount, int_CCCount;
                float fl_SalePremium;
                string str_NetPremium, str_GrossPremium, str_VAT, str_Duty, str_CNetPremium, str_CGrossPremium, str_CVAT, str_CDuty, str_DiscountToCustomer;
                string TotalNetPremium, TotalCNetPremium, TotalCollectedPremium, TotalBBLBankCharge, TotalVAT7, TotalBBLNetReceived;
                string OICVoluntaryTotal, OICCompulsoryTotal, OICFinalTotal, IntVoluntaryTotal, IntCompulsoryTotal, IntFinalTotal;
                string MktVoluntaryTotal, MktCompulsoryTotal, MktFinalTotal;
                string C_OICAZCP, C_OICAXA, C_OICBKI, C_OICCTS, C_OICKUR, C_OICLMG, C_OICMSIG, C_OICMTI, C_OICTMS, C_OICKPI;
                string C_IntAZCP, C_IntAXA, C_IntBKI, C_IntCTS, C_IntKUR, C_IntLMG, C_IntMSIG, C_IntMTI, C_IntTMS, C_IntKPI;
                string C_MktAZCP, C_MktAXA, C_MktBKI, C_MktCTS, C_MktKUR, C_MktLMG, C_MktMSIG, C_MktMTI, C_MktTMS, C_MktKPI;

                string V_OICAZCP, V_OICAXA, V_OICBKI, V_OICCTS, V_OICKUR, V_OICLMG, V_OICMSIG, V_OICMTI, V_OICTMS, V_OICKPI;
                string V_IntAZCP, V_IntAXA, V_IntBKI, V_IntCTS, V_IntKUR, V_IntLMG, V_IntMSIG, V_IntMTI, V_IntTMS, V_IntKPI;
                string V_MktAZCP, V_MktAXA, V_MktBKI, V_MktCTS, V_MktKUR, V_MktLMG, V_MktMSIG, V_MktMTI, V_MktTMS, V_MktKPI;

                string Total_OICAZCP, Total_OICAXA, Total_OICBKI, Total_OICCTS, Total_OICKUR, Total_OICLMG, Total_OICMSIG, Total_OICMTI, Total_OICTMS, Total_OICKPI;
                string Total_IntAZCP, Total_IntAXA, Total_IntBKI, Total_IntCTS, Total_IntKUR, Total_IntLMG, Total_IntMSIG, Total_IntMTI, Total_IntTMS, Total_IntKPI;
                string Total_MktAZCP, Total_MktAXA, Total_MktBKI, Total_MktCTS, Total_MktKUR, Total_MktLMG, Total_MktMSIG, Total_MktMTI, Total_MktTMS, Total_MktKPI;

                TotalNetPremium = "0"; TotalCNetPremium = "0"; TotalCollectedPremium = "0"; TotalBBLBankCharge = "0"; TotalVAT7 = "0"; TotalBBLNetReceived = "0";
                OICVoluntaryTotal = "0"; OICCompulsoryTotal = "0"; OICFinalTotal = "0"; IntVoluntaryTotal = "0"; IntCompulsoryTotal = "0"; IntFinalTotal = "0";
                MktVoluntaryTotal = "0"; MktCompulsoryTotal = "0"; MktFinalTotal = "0";
                C_OICAZCP = "0"; C_OICAXA = "0"; C_OICBKI = "0"; C_OICCTS = "0"; C_OICKUR = "0"; C_OICLMG = "0"; C_OICMSIG = "0"; C_OICMTI = "0"; C_OICTMS = "0"; C_OICKPI = "0";
                C_IntAZCP = "0"; C_IntAXA = "0"; C_IntBKI = "0"; C_IntCTS = "0"; C_IntKUR = "0"; C_IntLMG = "0"; C_IntMSIG = "0"; C_IntMTI = "0"; C_IntTMS = "0"; C_IntKPI = "0";
                C_MktAZCP = "0"; C_MktAXA = "0"; C_MktBKI = "0"; C_MktCTS = "0"; C_MktKUR = "0"; C_MktLMG = "0"; C_MktMSIG = "0"; C_MktMTI = "0"; C_MktTMS = "0"; C_MktKPI = "0";

                V_OICAZCP = "0"; V_OICAXA = "0"; V_OICBKI = "0"; V_OICCTS = "0"; V_OICKUR = "0"; V_OICLMG = "0"; V_OICMSIG = "0"; V_OICMTI = "0"; V_OICTMS = "0"; V_OICKPI = "0";
                V_IntAZCP = "0"; V_IntAXA = "0"; V_IntBKI = "0"; V_IntCTS = "0"; V_IntKUR = "0"; V_IntLMG = "0"; V_IntMSIG = "0"; V_IntMTI = "0"; V_IntTMS = "0"; V_IntKPI = "0";
                V_MktAZCP = "0"; V_MktAXA = "0"; V_MktBKI = "0"; V_MktCTS = "0"; V_MktKUR = "0"; V_MktLMG = "0"; V_MktMSIG = "0"; V_MktMTI = "0"; V_MktTMS = "0"; V_MktKPI = "0";

                Total_OICAZCP = "0"; Total_OICAXA = "0"; Total_OICBKI = "0"; Total_OICCTS = "0"; Total_OICKUR = "0"; Total_OICLMG = "0"; Total_OICMSIG = "0"; Total_OICMTI = "0"; Total_OICTMS = "0"; Total_OICKPI = "0";
                Total_IntAZCP = "0"; Total_IntAXA = "0"; Total_IntBKI = "0"; Total_IntCTS = "0"; Total_IntKUR = "0"; Total_IntLMG = "0"; Total_IntMSIG = "0"; Total_IntMTI = "0"; Total_IntTMS = "0"; Total_IntKPI = "0";
                Total_MktAZCP = "0"; Total_MktAXA = "0"; Total_MktBKI = "0"; Total_MktCTS = "0"; Total_MktKUR = "0"; Total_MktLMG = "0"; Total_MktMSIG = "0"; Total_MktMTI = "0"; Total_MktTMS = "0"; Total_MktKPI = "0";
                #endregion

                #region Default Value for OIC & Internal Reports
                //OIC
                OICInsurer[0] = GetProvider(16);
                OICInsurer[1] = GetProvider(11);
                OICInsurer[2] = GetProvider(32);
                OICInsurer[3] = GetProvider(31);
                OICInsurer[4] = GetProvider(35);
                OICInsurer[5] = GetProvider(41);
                OICInsurer[6] = GetProvider(29);
                OICInsurer[7] = GetProvider(12);
                OICInsurer[8] = GetProvider(33);
                OICInsurer[9] = GetProvider(46);

                OICVoluntary[0] = "0";
                OICVoluntary[1] = "0";
                OICVoluntary[2] = "0";
                OICVoluntary[3] = "0";
                OICVoluntary[4] = "0";
                OICVoluntary[5] = "0";
                OICVoluntary[6] = "0";
                OICVoluntary[7] = "0";
                OICVoluntary[8] = "0";
                OICVoluntary[9] = "0";

                OICCompulsory[0] = "0";
                OICCompulsory[1] = "0";
                OICCompulsory[2] = "0";
                OICCompulsory[3] = "0";
                OICCompulsory[4] = "0";
                OICCompulsory[5] = "0";
                OICCompulsory[6] = "0";
                OICCompulsory[7] = "0";
                OICCompulsory[8] = "0";
                OICCompulsory[9] = "0";

                OICTotal[0] = "0";
                OICTotal[1] = "0";
                OICTotal[2] = "0";
                OICTotal[3] = "0";
                OICTotal[4] = "0";
                OICTotal[5] = "0";
                OICTotal[6] = "0";
                OICTotal[7] = "0";
                OICTotal[8] = "0";
                OICTotal[9] = "0";

                //Internal
                IntInsurer[0] = GetProvider(16);
                IntInsurer[1] = GetProvider(11);
                IntInsurer[2] = GetProvider(32);
                IntInsurer[3] = GetProvider(31);
                IntInsurer[4] = GetProvider(35);
                IntInsurer[5] = GetProvider(41);
                IntInsurer[6] = GetProvider(29);
                IntInsurer[7] = GetProvider(12);
                IntInsurer[8] = GetProvider(33);
                IntInsurer[9] = GetProvider(46);

                IntVoluntary[0] = "0";
                IntVoluntary[1] = "0";
                IntVoluntary[2] = "0";
                IntVoluntary[3] = "0";
                IntVoluntary[4] = "0";
                IntVoluntary[5] = "0";
                IntVoluntary[6] = "0";
                IntVoluntary[7] = "0";
                IntVoluntary[8] = "0";
                IntVoluntary[9] = "0";

                IntCompulsory[0] = "0";
                IntCompulsory[1] = "0";
                IntCompulsory[2] = "0";
                IntCompulsory[3] = "0";
                IntCompulsory[4] = "0";
                IntCompulsory[5] = "0";
                IntCompulsory[6] = "0";
                IntCompulsory[7] = "0";
                IntCompulsory[8] = "0";
                IntCompulsory[9] = "0";

                IntTotal[0] = "0";
                IntTotal[1] = "0";
                IntTotal[2] = "0";
                IntTotal[3] = "0";
                IntTotal[4] = "0";
                IntTotal[5] = "0";
                IntTotal[6] = "0";
                IntTotal[7] = "0";
                IntTotal[8] = "0";
                IntTotal[9] = "0";

                //Marketing
                MktInsurer[0] = GetProvider(16);
                MktInsurer[1] = GetProvider(11);
                MktInsurer[2] = GetProvider(32);
                MktInsurer[3] = GetProvider(31);
                MktInsurer[4] = GetProvider(35);
                MktInsurer[5] = GetProvider(41);
                MktInsurer[6] = GetProvider(29);
                MktInsurer[7] = GetProvider(12);
                MktInsurer[8] = GetProvider(33);
                MktInsurer[9] = GetProvider(46);

                MktVoluntary[0] = "0";
                MktVoluntary[1] = "0";
                MktVoluntary[2] = "0";
                MktVoluntary[3] = "0";
                MktVoluntary[4] = "0";
                MktVoluntary[5] = "0";
                MktVoluntary[6] = "0";
                MktVoluntary[7] = "0";
                MktVoluntary[8] = "0";
                MktVoluntary[9] = "0";

                MktCompulsory[0] = "0";
                MktCompulsory[1] = "0";
                MktCompulsory[2] = "0";
                MktCompulsory[3] = "0";
                MktCompulsory[4] = "0";
                MktCompulsory[5] = "0";
                MktCompulsory[6] = "0";
                MktCompulsory[7] = "0";
                MktCompulsory[8] = "0";
                MktCompulsory[9] = "0";

                MktTotal[0] = "0";
                MktTotal[1] = "0";
                MktTotal[2] = "0";
                MktTotal[3] = "0";
                MktTotal[4] = "0";
                MktTotal[5] = "0";
                MktTotal[6] = "0";
                MktTotal[7] = "0";
                MktTotal[8] = "0";
                MktTotal[9] = "0";
                #endregion

                for (int i = 0; i < TotalFileCount; i++)
                {
                    #region Value Assign
                    fl_SalePremium = 0.0f;
                    str_NetPremium = "0";
                    str_GrossPremium = "0";
                    str_VAT = "0";
                    str_Duty = "0";
                    str_CNetPremium = "0";
                    str_CGrossPremium = "0";
                    str_CVAT = "0";
                    str_CDuty = "0";
                    str_DiscountToCustomer = "0";
                    int_PayCount = 0;
                    int_CCCount = 0;

                    QuoteRefNo[i] = _dtSummary.Rows[i]["QuoteRefNo"].ToString();
                    CECarId[i] = _dtSummary.Rows[i]["CECarId"].ToString();
                    ProviderCompanyId[i] = _dtSummary.Rows[i]["ProviderCompanyId"].ToString();
                    OrderDate[i] = _dtSummary.Rows[i]["OrderDate"].ToString();
                    CustomerType[i] = _dtSummary.Rows[i]["CustomerType"].ToString();
                    ApplicationName[i] = _dtSummary.Rows[i]["ApplicationName"].ToString();
                    Insurer[i] = _dtSummary.Rows[i]["Insurer"].ToString();
                    InsuranceType[i] = _dtSummary.Rows[i]["InsuranceType"].ToString();
                    InsuranceTypeId[i] = _dtSummary.Rows[i]["InsuranceTypeId"].ToString();
                    PolicyStartDate[i] = _dtSummary.Rows[i]["PolicyStartDate"].ToString();
                    PolicyEndDate[i] = _dtSummary.Rows[i]["PolicyEndDate"].ToString();
                    //SalesPremium[i] = _dtSummary.Rows[i]["Premium"].ToString();
                    CPolicyStartDate[i] = _dtSummary.Rows[i]["CTPLStartDate"].ToString();
                    CPolicyEndDate[i] = _dtSummary.Rows[i]["CTPLEndDate"].ToString();
                    CollectedPremium[i] = _dtSummary.Rows[i]["TotalCollectedPremium"].ToString();
                    Discount[i] = _dtSummary.Rows[i]["DiscountPercentage"].ToString() + "%";
                    Agent[i] = _dtSummary.Rows[i]["AgentName"].ToString();
                    IsCTPL[i] = _dtSummary.Rows[i]["IsCTPL"].ToString();
                    CTPL[i] = _dtSummary.Rows[i]["CTPL"].ToString();
                    GarageType[i] = _dtSummary.Rows[i]["GarageType"].ToString();

                    //fl_SalePremium = 54713.00f;
                    fl_SalePremium = Convert.ToSingle(_dtSummary.Rows[i]["SalesPremium"].ToString());
                    SalesPremium[i] = fl_SalePremium.ToString();
                    //str_NetPremium = Math.Ceiling(fl_SalePremium / 1.07).ToString();
                    //str_NetPremium = Math.Floor(Convert.ToSingle(str_NetPremium) / 1.004).ToString();
                    str_NetPremium = _dtSummary.Rows[i]["Premium"].ToString();
                    NetPremium[i] = str_NetPremium.ToString();
                    str_Duty = Math.Ceiling((Convert.ToSingle(str_NetPremium) * 0.004)).ToString();
                    Duty[i] = str_Duty.ToString();
                    str_VAT = Math.Round(((Convert.ToSingle(str_NetPremium) + Convert.ToSingle(str_Duty)) * 0.07), 2).ToString();
                    VAT[i] = str_VAT.ToString();
                    //str_GrossPremium = Math.Round((Convert.ToSingle(str_NetPremium) + Convert.ToSingle(str_Duty) + Convert.ToSingle(str_VAT)),2).ToString();
                    str_GrossPremium = _dtSummary.Rows[i]["GrossPremium"].ToString();
                    GrossPremium[i] = str_GrossPremium.ToString();

                    //if ("YES" == "YES")
                    if (_dtSummary.Rows[i]["IsCTPL"] != string.Empty && _dtSummary.Rows[i]["IsCTPL"].ToString().ToUpper() == "YES")
                    {
                        str_CGrossPremium = _dtSummary.Rows[i]["CTPL"].ToString();
                        CGrossPremium[i] = str_CGrossPremium.ToString();
                        str_CVAT = (Convert.ToSingle(str_CGrossPremium) / 1.07).ToString();
                        str_CVAT = Math.Round(Convert.ToSingle(str_CGrossPremium) - (Convert.ToSingle(str_CVAT)), 2).ToString();
                        CVAT[i] = str_CVAT.ToString();
                        str_CDuty = Math.Ceiling((Convert.ToSingle(str_CGrossPremium) / 1.07) * 0.004).ToString();
                        CDuty[i] = str_CDuty.ToString();
                        str_CNetPremium = (Convert.ToSingle(str_CGrossPremium) - (Convert.ToSingle(str_CDuty) + Convert.ToSingle(str_CVAT))).ToString();
                        CNetPremium[i] = str_CNetPremium.ToString();
                    }
                    else
                    {
                        CVAT[i] = " ";
                        CDuty[i] = " ";
                        CNetPremium[i] = " ";
                        CGrossPremium[i] = " ";
                    }
                    //str_DiscountToCustomer = Math.Round(((Convert.ToSingle(fl_SalePremium) + Convert.ToSingle(str_CGrossPremium)) - Convert.ToSingle(13718.00)), 2).ToString();
                    str_DiscountToCustomer = Math.Round(((Convert.ToSingle(fl_SalePremium) + Convert.ToSingle(str_CGrossPremium)) - Convert.ToSingle(CollectedPremium[i].ToString())), 2).ToString();
                    DiscounttoCustomer[i] = str_DiscountToCustomer.ToString();
                    Bank[i] = "BBL";
                    MethodofPayment[i] = " ";
                    BBLBankCharge[i] = "0";
                    VAT7[i] = "0";
                    BBLNetReceived[i] = "0";
                    Remark[i] = " ";
                    PremiumReceivingDate[i] = " ";
                    if (_dsSummary != null && _dsSummary.Tables.Count > 1 && _dsSummary.Tables[1].Rows.Count > 0)
                    {
                        string _PayDetails = GetPaymentDetailList(Convert.ToInt64(CECarId[i].ToString()), Convert.ToInt64(ProviderCompanyId[i].ToString()), CollectedPremium[i].ToString());
                        string[] _PayDetail = _PayDetails.Split('@');
                        if (_PayDetail.Length > 1)
                        {
                            MethodofPayment[i] = _PayDetail[0].ToString();
                            PremiumReceivingDate[i] = _PayDetail[1].ToString();
                        }
                        if (_PayDetail.Length > 4)
                        {
                            if (_PayDetail[2].ToString().Trim() != string.Empty)
                            {
                                if (_PayDetail[2].ToString().Trim() != "0" && _PayDetail[2].ToString().Trim() != "0.00")
                                {
                                    BBLBankCharge[i] = _PayDetail[2].ToString().Trim();
                                }
                                else
                                {
                                    BBLBankCharge[i] = " ";
                                }
                            }
                            if (_PayDetail[3].ToString().Trim() != string.Empty)
                            {
                                if (_PayDetail[3].ToString().Trim() != "0" && _PayDetail[3].ToString().Trim() != "0.00")
                                {
                                    VAT7[i] = _PayDetail[3].ToString().Trim();
                                }
                                else
                                {
                                    VAT7[i] = " ";
                                }
                            }
                            if (_PayDetail[4].ToString().Trim() != string.Empty)
                            {
                                BBLNetReceived[i] = _PayDetail[4].ToString().Trim();
                            }
                        }
                    }
                    if (_dsSummary != null && _dsSummary.Tables.Count > 2 && _dsSummary.Tables[2].Rows.Count > 0)
                    {
                        Remark[i] = GetRemarks(QuoteRefNo[i].ToString(), 200);// _dsSummary.Tables[2].Rows[0]["Remarks"].ToString();
                    }
                    if (str_NetPremium.ToString().Trim() != string.Empty)
                    {
                        TotalNetPremium = (Convert.ToSingle(TotalNetPremium) + Convert.ToSingle(str_NetPremium)).ToString();
                    }
                    if (str_CNetPremium.ToString().Trim() != string.Empty)
                    {
                        TotalCNetPremium = (Convert.ToSingle(TotalCNetPremium) + Convert.ToSingle(str_CNetPremium)).ToString();
                    }
                    if (CollectedPremium[i].ToString().Trim() != string.Empty)
                    {
                        TotalCollectedPremium = (Convert.ToSingle(TotalCollectedPremium) + Convert.ToSingle(CollectedPremium[i].ToString())).ToString();
                    }
                    if (BBLBankCharge[i].ToString().Trim() != string.Empty)
                    {
                        TotalBBLBankCharge = (Convert.ToSingle(TotalBBLBankCharge) + Convert.ToSingle(BBLBankCharge[i].ToString().Trim())).ToString();
                    }
                    if (VAT7[i].ToString().Trim() != string.Empty)
                    {
                        TotalVAT7 = (Convert.ToSingle(TotalVAT7) + Convert.ToSingle(VAT7[i].ToString().Trim())).ToString();
                    }
                    if (BBLNetReceived[i].ToString().Trim() != string.Empty)
                    {
                        TotalBBLNetReceived = (Convert.ToSingle(TotalBBLNetReceived) + Convert.ToSingle(BBLNetReceived[i].ToString().Trim())).ToString();
                    }
                    #endregion

                    #region Value for OIC & Internal Reports
                    float _IntPer = 0.0f;
                    float _MktPer = 0.0f;
                    float _OICPer = 0.0f;
                    DataTable _dtPer = new DataTable();
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "16")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(16, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntAXA = (Convert.ToSingle(C_IntAXA) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktAXA = (Convert.ToSingle(C_MktAXA) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICAXA = (Convert.ToSingle(C_OICAXA) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            _dtPer = GetPercentage(16, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAXA = (Convert.ToSingle(V_IntAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAXA = (Convert.ToSingle(V_MktAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAXA = (Convert.ToSingle(V_OICAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() != "10" || InsuranceTypeId[i].ToString().Trim() != "11"))
                        {
                            _dtPer = GetPercentage(16, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAXA = (Convert.ToSingle(V_IntAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAXA = (Convert.ToSingle(V_MktAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAXA = (Convert.ToSingle(V_OICAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntAXA = ((Convert.ToSingle(V_IntAXA)) + (Convert.ToSingle(C_IntAXA))).ToString();
                        Total_MktAXA = ((Convert.ToSingle(V_MktAXA)) + (Convert.ToSingle(C_MktAXA))).ToString();
                        Total_OICAXA = ((Convert.ToSingle(V_OICAXA)) + (Convert.ToSingle(C_OICAXA))).ToString();
                    }
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "11")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(11, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntAZCP = (Convert.ToSingle(C_IntAZCP) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktAZCP = (Convert.ToSingle(C_IntAZCP) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICAZCP = (Convert.ToSingle(C_IntAZCP) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11") && GarageType[i].ToString().Trim() == "1")
                        {
                            _dtPer = GetPercentage(11, "VMI", 1011, 1, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAZCP = (Convert.ToSingle(V_IntAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAZCP = (Convert.ToSingle(V_MktAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAZCP = (Convert.ToSingle(V_OICAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11") && GarageType[i].ToString().Trim() == "2")
                        {
                            _dtPer = GetPercentage(11, "VMI", 1011, 2, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAZCP = (Convert.ToSingle(V_IntAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAZCP = (Convert.ToSingle(V_MktAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAZCP = (Convert.ToSingle(V_OICAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "21" && InsuranceTypeId[i].ToString().Trim() == "31")
                        {
                            _dtPer = GetPercentage(11, "VMI", 2131, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAZCP = (Convert.ToSingle(V_IntAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAZCP = (Convert.ToSingle(V_MktAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAZCP = (Convert.ToSingle(V_OICAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "30")
                        {
                            _dtPer = GetPercentage(11, "VMI", 30, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAZCP = (Convert.ToSingle(V_IntAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAZCP = (Convert.ToSingle(V_MktAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAZCP = (Convert.ToSingle(V_OICAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntAZCP = ((Convert.ToSingle(V_IntAZCP)) + (Convert.ToSingle(C_IntAZCP))).ToString();
                        Total_MktAZCP = ((Convert.ToSingle(V_MktAZCP)) + (Convert.ToSingle(C_MktAZCP))).ToString();
                        Total_OICAZCP = ((Convert.ToSingle(V_OICAZCP)) + (Convert.ToSingle(C_OICAZCP))).ToString();
                    }
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "32")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(32, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntBKI = (Convert.ToSingle(C_IntBKI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktBKI = (Convert.ToSingle(C_MktBKI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICBKI = (Convert.ToSingle(C_OICBKI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(32, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());


                            V_IntBKI = (Convert.ToSingle(V_IntBKI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktBKI = (Convert.ToSingle(V_MktBKI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICBKI = (Convert.ToSingle(V_OICBKI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntBKI = ((Convert.ToSingle(V_IntBKI)) + (Convert.ToSingle(C_IntBKI))).ToString();
                        Total_MktBKI = ((Convert.ToSingle(V_MktBKI)) + (Convert.ToSingle(C_MktBKI))).ToString();
                        Total_OICBKI = ((Convert.ToSingle(V_OICBKI)) + (Convert.ToSingle(C_OICBKI))).ToString();
                    }
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "31")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(31, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntCTS = (Convert.ToSingle(C_IntCTS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktCTS = (Convert.ToSingle(C_MktCTS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICCTS = (Convert.ToSingle(C_OICCTS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(31, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                            V_IntCTS = (Convert.ToSingle(V_IntCTS) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktCTS = (Convert.ToSingle(V_MktCTS) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICCTS = (Convert.ToSingle(V_OICCTS) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntCTS = ((Convert.ToSingle(V_IntCTS)) + (Convert.ToSingle(C_IntCTS))).ToString();
                        Total_MktCTS = ((Convert.ToSingle(V_MktCTS)) + (Convert.ToSingle(C_MktCTS))).ToString();
                        Total_OICCTS = ((Convert.ToSingle(V_OICCTS)) + (Convert.ToSingle(C_OICCTS))).ToString();
                    }
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "41")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(41, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntKUR = (Convert.ToSingle(C_IntKUR) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktKUR = (Convert.ToSingle(C_MktKUR) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICKUR = (Convert.ToSingle(C_OICKUR) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() != "11")
                        {
                            _dtPer = GetPercentage(41, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntKUR = (Convert.ToSingle(V_IntKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktKUR = (Convert.ToSingle(V_MktKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICKUR = (Convert.ToSingle(V_OICKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "11")
                        {
                            _dtPer = GetPercentage(41, "VMI", 11, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntKUR = (Convert.ToSingle(V_IntKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktKUR = (Convert.ToSingle(V_MktKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICKUR = (Convert.ToSingle(V_OICKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntKUR = ((Convert.ToSingle(V_IntKUR)) + (Convert.ToSingle(C_IntKUR))).ToString();
                        Total_MktKUR = ((Convert.ToSingle(V_MktKUR)) + (Convert.ToSingle(C_MktKUR))).ToString();
                        Total_OICKUR = ((Convert.ToSingle(V_OICKUR)) + (Convert.ToSingle(C_OICKUR))).ToString();
                    }
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "29")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(29, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntLMG = (Convert.ToSingle(C_IntLMG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktLMG = (Convert.ToSingle(C_MktLMG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICLMG = (Convert.ToSingle(C_OICLMG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            _dtPer = GetPercentage(29, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntLMG = (Convert.ToSingle(V_IntLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktLMG = (Convert.ToSingle(V_MktLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICLMG = (Convert.ToSingle(V_OICLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() != "10" || InsuranceTypeId[i].ToString().Trim() != "11"))
                        {
                            _dtPer = GetPercentage(29, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntLMG = (Convert.ToSingle(V_IntLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktLMG = (Convert.ToSingle(V_MktLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICLMG = (Convert.ToSingle(V_OICLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntLMG = ((Convert.ToSingle(V_IntLMG)) + (Convert.ToSingle(C_IntLMG))).ToString();
                        Total_MktLMG = ((Convert.ToSingle(V_MktLMG)) + (Convert.ToSingle(C_MktLMG))).ToString();
                        Total_OICLMG = ((Convert.ToSingle(V_OICLMG)) + (Convert.ToSingle(C_OICLMG))).ToString();
                    }
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "12")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(12, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntMSIG = (Convert.ToSingle(C_IntMSIG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktMSIG = (Convert.ToSingle(C_MktMSIG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICMSIG = (Convert.ToSingle(C_OICMSIG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(12, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                            V_IntMSIG = (Convert.ToSingle(V_IntMSIG) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktMSIG = (Convert.ToSingle(V_MktMSIG) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICMSIG = (Convert.ToSingle(V_OICMSIG) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntMSIG = ((Convert.ToSingle(V_IntMSIG)) + (Convert.ToSingle(C_IntMSIG))).ToString();
                        Total_MktMSIG = ((Convert.ToSingle(V_MktMSIG)) + (Convert.ToSingle(C_MktMSIG))).ToString();
                        Total_OICMSIG = ((Convert.ToSingle(V_OICMSIG)) + (Convert.ToSingle(C_OICMSIG))).ToString();
                    }
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "33")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(33, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntMTI = (Convert.ToSingle(C_IntMTI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktMTI = (Convert.ToSingle(C_IntMTI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICMTI = (Convert.ToSingle(C_IntMTI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            _dtPer = GetPercentage(33, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntMTI = (Convert.ToSingle(V_IntMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktMTI = (Convert.ToSingle(V_MktMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICMTI = (Convert.ToSingle(V_OICMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "21" && InsuranceTypeId[i].ToString().Trim() == "31")
                        {
                            _dtPer = GetPercentage(33, "VMI", 2131, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntMTI = (Convert.ToSingle(V_IntMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktMTI = (Convert.ToSingle(V_MktMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICMTI = (Convert.ToSingle(V_OICMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "30")
                        {
                            _dtPer = GetPercentage(33, "VMI", 30, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntMTI = (Convert.ToSingle(V_IntMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktMTI = (Convert.ToSingle(V_MktMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICMTI = (Convert.ToSingle(V_OICMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntMTI = ((Convert.ToSingle(V_IntMTI)) + (Convert.ToSingle(C_IntMTI))).ToString();
                        Total_MktMTI = ((Convert.ToSingle(V_MktMTI)) + (Convert.ToSingle(C_MktMTI))).ToString();
                        Total_OICMTI = ((Convert.ToSingle(V_OICMTI)) + (Convert.ToSingle(C_OICMTI))).ToString();
                    }
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "46")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(46, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntTMS = (Convert.ToSingle(C_IntTMS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktTMS = (Convert.ToSingle(C_MktTMS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICTMS = (Convert.ToSingle(C_OICTMS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            _dtPer = GetPercentage(46, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntTMS = (Convert.ToSingle(V_IntTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktTMS = (Convert.ToSingle(V_MktTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICTMS = (Convert.ToSingle(V_OICTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() != "10" || InsuranceTypeId[i].ToString().Trim() != "11"))
                        {
                            _dtPer = GetPercentage(46, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntTMS = (Convert.ToSingle(V_IntTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktTMS = (Convert.ToSingle(V_MktTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICTMS = (Convert.ToSingle(V_OICTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntTMS = ((Convert.ToSingle(V_IntTMS)) + (Convert.ToSingle(C_IntTMS))).ToString();
                        Total_MktTMS = ((Convert.ToSingle(V_MktTMS)) + (Convert.ToSingle(C_MktTMS))).ToString();
                        Total_OICTMS = ((Convert.ToSingle(V_OICTMS)) + (Convert.ToSingle(C_OICTMS))).ToString();
                    }
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "35")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(35, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntKPI = (Convert.ToSingle(C_IntKPI) + Math.Round((Convert.ToSingle(0) * _IntPer), 2)).ToString();
                                C_MktKPI = (Convert.ToSingle(C_MktKPI) + Math.Round((Convert.ToSingle(0) * _MktPer), 2)).ToString();
                                C_OICKPI = (Convert.ToSingle(C_OICKPI) + Math.Round((Convert.ToSingle(0) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(35, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                            V_IntKPI = (Convert.ToSingle(V_IntKPI) + Math.Round((Convert.ToSingle(0) * _IntPer), 2)).ToString();
                            V_MktKPI = (Convert.ToSingle(V_MktKPI) + Math.Round((Convert.ToSingle(0) * _MktPer), 2)).ToString();
                            V_OICKPI = (Convert.ToSingle(V_OICKPI) + Math.Round((Convert.ToSingle(0) * _OICPer), 2)).ToString();
                        }

                        Total_IntKPI = ((Convert.ToSingle(V_IntKPI)) + (Convert.ToSingle(C_IntKPI))).ToString();
                        Total_MktKPI = ((Convert.ToSingle(V_MktKPI)) + (Convert.ToSingle(C_MktKPI))).ToString();
                        Total_OICKPI = ((Convert.ToSingle(V_OICKPI)) + (Convert.ToSingle(C_OICKPI))).ToString();
                    }
                    #endregion

                    #region Testing - Removed
                    //string _strBBLCharge, _strVAT7, _strBBLNetReceived, _Details;
                    //_strBBLCharge= "0";
                    //_strVAT7 = "0"; 
                    //_strBBLNetReceived = "0"; 
                    //_Details = "0";
                    //float fl_CollectedPremium = 13718.00f;
                    //_strBBLCharge = (fl_CollectedPremium * 0.03).ToString();
                    //_strBBLCharge = Math.Round(Convert.ToSingle(_strBBLCharge), 2).ToString();
                    //_strVAT7 = Math.Round((Convert.ToSingle(_strBBLCharge) * 0.07), 2).ToString();
                    //_strBBLNetReceived = Math.Round((Convert.ToSingle(fl_CollectedPremium) - Convert.ToSingle(0) - Convert.ToSingle(0)), 2).ToString();
                    //_Details = _Details + "/" + _strBBLCharge + "/" + _strVAT7 + "/" + _strBBLNetReceived;
                    #endregion
                }

                #region Assign Value for OIC & Internal Reports
                OICVoluntaryTotal = (Convert.ToSingle(V_OICAZCP) + Convert.ToSingle(V_OICAXA) + Convert.ToSingle(V_OICBKI) + Convert.ToSingle(V_OICCTS) + Convert.ToSingle(V_OICKUR)
                                    + Convert.ToSingle(V_OICAXA) + Convert.ToSingle(V_OICLMG) + Convert.ToSingle(V_OICMSIG) + Convert.ToSingle(V_OICTMS) + Convert.ToSingle(V_OICKPI)).ToString();
                OICCompulsoryTotal = (Convert.ToSingle(C_OICAZCP) + Convert.ToSingle(C_OICAXA) + Convert.ToSingle(C_OICBKI) + Convert.ToSingle(C_OICCTS) + Convert.ToSingle(C_OICKUR)
                                    + Convert.ToSingle(C_OICAXA) + Convert.ToSingle(C_OICLMG) + Convert.ToSingle(C_OICMSIG) + Convert.ToSingle(C_OICTMS) + Convert.ToSingle(C_OICKPI)).ToString();
                OICFinalTotal = (Convert.ToSingle(Total_OICAZCP) + Convert.ToSingle(Total_OICAXA) + Convert.ToSingle(Total_OICBKI) + Convert.ToSingle(Total_OICCTS) + Convert.ToSingle(Total_OICKUR)
                                    + Convert.ToSingle(Total_OICAXA) + Convert.ToSingle(Total_OICLMG) + Convert.ToSingle(Total_OICMSIG) + Convert.ToSingle(Total_OICTMS) + Convert.ToSingle(Total_OICKPI)).ToString();

                IntVoluntaryTotal = (Convert.ToSingle(V_IntAZCP) + Convert.ToSingle(V_IntAXA) + Convert.ToSingle(V_IntBKI) + Convert.ToSingle(V_IntCTS) + Convert.ToSingle(V_IntKUR)
                                    + Convert.ToSingle(V_IntAXA) + Convert.ToSingle(V_IntLMG) + Convert.ToSingle(V_IntMSIG) + Convert.ToSingle(V_IntTMS) + Convert.ToSingle(V_IntKPI)).ToString();
                IntCompulsoryTotal = (Convert.ToSingle(C_IntAZCP) + Convert.ToSingle(C_IntAXA) + Convert.ToSingle(C_IntBKI) + Convert.ToSingle(C_IntCTS) + Convert.ToSingle(C_IntKUR)
                                    + Convert.ToSingle(C_IntAXA) + Convert.ToSingle(C_IntLMG) + Convert.ToSingle(C_IntMSIG) + Convert.ToSingle(C_IntTMS) + Convert.ToSingle(C_IntKPI)).ToString();
                IntFinalTotal = (Convert.ToSingle(Total_IntAZCP) + Convert.ToSingle(Total_IntAXA) + Convert.ToSingle(Total_IntBKI) + Convert.ToSingle(Total_IntCTS) + Convert.ToSingle(Total_IntKUR)
                                    + Convert.ToSingle(Total_IntAXA) + Convert.ToSingle(Total_IntLMG) + Convert.ToSingle(Total_IntMSIG) + Convert.ToSingle(Total_IntTMS) + Convert.ToSingle(Total_IntKPI)).ToString();

                MktVoluntaryTotal = (Convert.ToSingle(V_MktAZCP) + Convert.ToSingle(V_MktAXA) + Convert.ToSingle(V_MktBKI) + Convert.ToSingle(V_MktCTS) + Convert.ToSingle(V_MktKUR)
                                    + Convert.ToSingle(V_MktAXA) + Convert.ToSingle(V_MktLMG) + Convert.ToSingle(V_MktMSIG) + Convert.ToSingle(V_MktTMS) + Convert.ToSingle(V_MktKPI)).ToString();
                MktCompulsoryTotal = (Convert.ToSingle(C_MktAZCP) + Convert.ToSingle(C_MktAXA) + Convert.ToSingle(C_MktBKI) + Convert.ToSingle(C_MktCTS) + Convert.ToSingle(C_MktKUR)
                                    + Convert.ToSingle(C_MktAXA) + Convert.ToSingle(C_MktLMG) + Convert.ToSingle(C_MktMSIG) + Convert.ToSingle(C_MktTMS) + Convert.ToSingle(C_MktKPI)).ToString();
                MktFinalTotal = (Convert.ToSingle(Total_MktAZCP) + Convert.ToSingle(Total_MktAXA) + Convert.ToSingle(Total_MktBKI) + Convert.ToSingle(Total_MktCTS) + Convert.ToSingle(Total_MktKUR)
                                    + Convert.ToSingle(Total_MktAXA) + Convert.ToSingle(Total_MktLMG) + Convert.ToSingle(Total_MktMSIG) + Convert.ToSingle(Total_MktTMS) + Convert.ToSingle(Total_MktKPI)).ToString();
                //OIC
                OICVoluntary[0] = V_OICAXA.ToString();
                OICVoluntary[1] = V_OICAZCP.ToString();
                OICVoluntary[2] = V_OICBKI.ToString();
                OICVoluntary[3] = V_OICCTS.ToString();
                OICVoluntary[4] = V_OICKPI.ToString();
                OICVoluntary[5] = V_OICKUR.ToString();
                OICVoluntary[6] = V_OICLMG.ToString();
                OICVoluntary[7] = V_OICMSIG.ToString();
                OICVoluntary[8] = V_OICMTI.ToString();
                OICVoluntary[9] = V_OICTMS.ToString();

                OICCompulsory[0] = C_OICAXA.ToString();
                OICCompulsory[1] = C_OICAZCP.ToString();
                OICCompulsory[2] = C_OICBKI.ToString();
                OICCompulsory[3] = C_OICCTS.ToString();
                OICCompulsory[4] = C_OICKPI.ToString();
                OICCompulsory[5] = C_OICKUR.ToString();
                OICCompulsory[6] = C_OICLMG.ToString();
                OICCompulsory[7] = C_OICMSIG.ToString();
                OICCompulsory[8] = C_OICMTI.ToString();
                OICCompulsory[9] = C_OICTMS.ToString();

                OICTotal[0] = Total_OICAXA.ToString();
                OICTotal[1] = Total_OICAZCP.ToString();
                OICTotal[2] = Total_OICBKI.ToString();
                OICTotal[3] = Total_OICCTS.ToString();
                OICTotal[4] = Total_OICKPI.ToString();
                OICTotal[5] = Total_OICKUR.ToString();
                OICTotal[6] = Total_OICLMG.ToString();
                OICTotal[7] = Total_OICMSIG.ToString();
                OICTotal[8] = Total_OICMTI.ToString();
                OICTotal[9] = Total_OICTMS.ToString();

                //Intenal
                IntVoluntary[0] = V_IntAXA.ToString();
                IntVoluntary[1] = V_IntAZCP.ToString();
                IntVoluntary[2] = V_IntBKI.ToString();
                IntVoluntary[3] = V_IntCTS.ToString();
                IntVoluntary[4] = V_IntKPI.ToString();
                IntVoluntary[5] = V_IntKUR.ToString();
                IntVoluntary[6] = V_IntLMG.ToString();
                IntVoluntary[7] = V_IntMSIG.ToString();
                IntVoluntary[8] = V_IntMTI.ToString();
                IntVoluntary[9] = V_IntTMS.ToString();

                IntCompulsory[0] = C_IntAXA.ToString();
                IntCompulsory[1] = C_IntAZCP.ToString();
                IntCompulsory[2] = C_IntBKI.ToString();
                IntCompulsory[3] = C_IntCTS.ToString();
                IntCompulsory[4] = C_IntKPI.ToString();
                IntCompulsory[5] = C_IntKUR.ToString();
                IntCompulsory[6] = C_IntLMG.ToString();
                IntCompulsory[7] = C_IntMSIG.ToString();
                IntCompulsory[8] = C_IntMTI.ToString();
                IntCompulsory[9] = C_IntTMS.ToString();

                IntTotal[0] = Total_IntAXA.ToString();
                IntTotal[1] = Total_IntAZCP.ToString();
                IntTotal[2] = Total_IntBKI.ToString();
                IntTotal[3] = Total_IntCTS.ToString();
                IntTotal[4] = Total_IntKPI.ToString();
                IntTotal[5] = Total_IntKUR.ToString();
                IntTotal[6] = Total_IntLMG.ToString();
                IntTotal[7] = Total_IntMSIG.ToString();
                IntTotal[8] = Total_IntMTI.ToString();
                IntTotal[9] = Total_IntTMS.ToString();

                //Marketing
                MktVoluntary[0] = V_MktAXA.ToString();
                MktVoluntary[1] = V_MktAZCP.ToString();
                MktVoluntary[2] = V_MktBKI.ToString();
                MktVoluntary[3] = V_MktCTS.ToString();
                MktVoluntary[4] = V_MktKPI.ToString();
                MktVoluntary[5] = V_MktKUR.ToString();
                MktVoluntary[6] = V_MktLMG.ToString();
                MktVoluntary[7] = V_MktMSIG.ToString();
                MktVoluntary[8] = V_MktMTI.ToString();
                MktVoluntary[9] = V_MktTMS.ToString();

                MktCompulsory[0] = C_MktAXA.ToString();
                MktCompulsory[1] = C_MktAZCP.ToString();
                MktCompulsory[2] = C_MktBKI.ToString();
                MktCompulsory[3] = C_MktCTS.ToString();
                MktCompulsory[4] = C_MktKPI.ToString();
                MktCompulsory[5] = C_MktKUR.ToString();
                MktCompulsory[6] = C_MktLMG.ToString();
                MktCompulsory[7] = C_MktMSIG.ToString();
                MktCompulsory[8] = C_MktMTI.ToString();
                MktCompulsory[9] = C_MktTMS.ToString();

                MktTotal[0] = Total_MktAXA.ToString();
                MktTotal[1] = Total_MktAZCP.ToString();
                MktTotal[2] = Total_MktBKI.ToString();
                MktTotal[3] = Total_MktCTS.ToString();
                MktTotal[4] = Total_MktKPI.ToString();
                MktTotal[5] = Total_MktKUR.ToString();
                MktTotal[6] = Total_MktLMG.ToString();
                MktTotal[7] = Total_MktMSIG.ToString();
                MktTotal[8] = Total_MktMTI.ToString();
                MktTotal[9] = Total_MktTMS.ToString();

                #endregion

                #region Generate Excel
                string ReportMonth = "";
                if (_ReportType == 0)
                {
                    ReportMonth = GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                else if (_ReportType == 1)
                {
                    ReportMonth = ddlDay1.Text + " " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                _html += "<html>";
                _html += "<head>";
                _html += "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>"; 
                _html += "</head>";
                _html += "<body>";
                _html += "<table width='100%' cellpadding='1' cellspacing='1' border='1'>";
                _html += "<tr><td align='left' colspan='29' style='font-size:20px; background-color:#D8D8D8;'><b>" + Resources.General.SalesSummary + " (" + ReportMonth + ")</b></td></tr>";
                //_html += "<tr><td align='left' colspan='30' style='font-size:20px; background-color:#D8D8D8;'><b>" + Resources.General.SalesSummary + " (" + ReportMonth + ")</b></td></tr>";
                _html += "<tr>";
                _html += "<td colspan='5'>&nbsp;</td>";
                //_html += "<td colspan='6'>&nbsp;</td>";
                _html += "<td colspan='7' align='center' style='background-color:#fffe97;'><b>" + Resources.NonGG.Voluntary + "</b></td>";
                _html += "<td colspan='6' align='center' style='background-color:#cbffce;'><b>" + Resources.NonGG.Compulsory + "</b></td>";
                _html += "<td colspan='5'>&nbsp;</td>";
                _html += "<td colspan='6' align='center' style='background-color:#c9ffff;'><b>" + Resources.NonGG.BankStatement + "</b></td>";
                _html += "</tr>";
                _html += "<tr>";
                _html += "<td width='80' align='left' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.OrderDate + "</b></td>";
                _html += "<td width='90' align='left' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.General.ReferenceNo + "</b></td>";
                _html += "<td width='110' align='left' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.CustomerType + "</b></td>";
                //_html += "<td width='200' align='left' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.ApplicationName + "</b></td>";
                _html += "<td width='70' align='left' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.Insurer + "</b></td>";
                _html += "<td width='100' align='left' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.InsuranceType + "</b></td>";
                _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.PolicyStartDate + "</b></td>";
                _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.PolicyEndDate + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.SalesPremium + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.GrossPremium + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.NetPremium + "</b></td>";
                _html += "<td width='60' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.Duty + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.VAT + "</b></td>";
                _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.PolicyStartDate + "</b></td>";
                _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.PolicyEndDate + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.NetPremium + "</b></td>";
                _html += "<td width='60' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.Duty + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.VAT + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.GrossPremium + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.CollectedPremium + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.DiscounttoCustomer + "</b></td>";
                _html += "<td width='70' align='left' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.Discount + "</b></td>";
                _html += "<td width='130' align='left' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.Agent + "</b></td>";
                _html += "<td width='200' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.Remark + "</b></td>";
                _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.PremiumReceiveingDate + "</b></td>";
                _html += "<td width='60' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.Bank + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.MethodofPayment + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.BBLBankCharge + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.VAT7 + "</b></td>";
                _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>" + Resources.NonGG.BBLNetReceived + "</b></td>";
                _html += "</tr>";

                for (int j = 0; j < TotalFileCount; j++)
                {
                    _html += "<tr>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + OrderDate[j].ToString() + "</td>";
                    _html += "<td width='90' align='left'>" + QuoteRefNo[j].ToString() + "</td>";
                    _html += "<td width='110' align='left'>" + CustomerType[j].ToString() + "</td>";
                    //_html += "<td width='200' align='left'>" + ApplicationName[j].ToString() + "</td>";
                    _html += "<td width='70' align='left'>" + Insurer[j].ToString() + "</td>";
                    _html += "<td width='100' align='left'>" + InsuranceType[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + PolicyStartDate[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + PolicyEndDate[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + SalesPremium[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + GrossPremium[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + NetPremium[j].ToString() + "</td>";
                    _html += "<td width='60' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + Duty[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + VAT[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + CPolicyStartDate[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + CPolicyEndDate[j].ToString() + "</td>";
                    if (IsCTPL[j].ToString().ToUpper() == "YES")
                    {
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CNetPremium[j].ToString() + "</td>";
                        _html += "<td width='60' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CDuty[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CVAT[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CGrossPremium[j].ToString() + "</td>";
                    }
                    else
                    {
                        _html += "<td width='100' align='left'>" + CNetPremium[j].ToString() + "</td>";
                        _html += "<td width='60' align='left'>" + CDuty[j].ToString() + "</td>";
                        _html += "<td width='100' align='left'>" + CVAT[j].ToString() + "</td>";
                        _html += "<td width='100' align='left'>" + CGrossPremium[j].ToString() + "</td>";
                    }
                    _html += "<td width='100' align='right' style='background-color:#fffe97; mso-number-format:\\#\\,\\#\\#0\\.00'>" + CollectedPremium[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + DiscounttoCustomer[j].ToString() + "</td>";
                    _html += "<td width='70' align='left'>" + Discount[j].ToString() + "</td>";
                    _html += "<td width='130' align='left'>" + Agent[j].ToString() + "</td>";
                    _html += "<td width='200' align='left'>" + Remark[j].ToString() + "</td>";
                    if (PremiumReceivingDate[j].ToString() == string.Empty)
                    {
                        _html += "<td width='80' align='left'>" + PremiumReceivingDate[j].ToString() + "</td>";
                    }
                    else
                    {
                        _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy'>" + PremiumReceivingDate[j].ToString() + "</td>";
                    }
                    _html += "<td width='60' align='left'>" + Bank[j].ToString() + "</td>";
                    _html += "<td width='100' align='left'>" + MethodofPayment[j].ToString() + "</td>";
                    if (BBLBankCharge[j].ToString().Trim() != string.Empty && BBLBankCharge[j].ToString().Trim() != "0")
                    {
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + BBLBankCharge[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + VAT7[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + BBLNetReceived[j].ToString() + "</td>";
                    }
                    else
                    {
                        _html += "<td width='100' align='right'>" + BBLBankCharge[j].ToString() + "</td>";
                        _html += "<td width='100' align='right'>" + VAT7[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + BBLNetReceived[j].ToString() + "</td>";
                    }
                    _html += "</tr>";
                }
                _html += "<tr>";
                _html += "<td colspan='9' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                //_html += "<td colspan='10' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalNetPremium.ToString() + "</b></td>";
                _html += "<td colspan='4' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalCNetPremium.ToString() + "</b></td>";
                _html += "<td colspan='3' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalCollectedPremium.ToString() + "</b></td>";
                _html += "<td colspan='7' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalBBLBankCharge.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalVAT7.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalBBLNetReceived.ToString() + "</b></td>";
                _html += "</tr>";

                _html += "</table>";

                _html += "<table width='20%' cellpadding='1' cellspacing='1'>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "</table>";

                //OIC
                _html += "<table width='25%' cellpadding='1' cellspacing='1' border='1'>";
                _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>" + Resources.NonGG.OICReporting + "</b></td></tr>";
                _html += "<tr>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Insurer + "</b></td>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Voluntary + "</b></td>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Compulsory + "</b></td>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Total + "</b></td>";
                _html += "</tr>";

                for (int b = 0; b < 10; b++)
                {
                    _html += "<tr>";
                    _html += "<td align='center'><b>" + OICInsurer[b].ToString() + "</b></td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICVoluntary[b].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICCompulsory[b].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICTotal[b].ToString() + "</td>";
                    _html += "</tr>";
                }

                _html += "<tr>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100;'><b>&nbsp;</b></td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICVoluntaryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICCompulsoryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICFinalTotal.ToString() + "</td>";
                _html += "</tr>";

                _html += "</table>";

                _html += "<table width='25%' cellpadding='1' cellspacing='1'>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "</table>";

                //Internal
                _html += "<table width='20%' cellpadding='1' cellspacing='1' border='1'>";
                _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>" + Resources.NonGG.InternalReporting + "</b></td></tr>";
                _html += "<tr>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Insurer + "</b></td>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Voluntary + "</b></td>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Compulsory + "</b></td>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Total + "</b></td>";
                _html += "</tr>";

                for (int c = 0; c < 10; c++)
                {
                    _html += "<tr>";
                    _html += "<td align='center'><b>" + IntInsurer[c].ToString() + "</b></td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntVoluntary[c].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntCompulsory[c].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntTotal[c].ToString() + "</td>";
                    _html += "</tr>";
                }

                _html += "<tr>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100;'><b>&nbsp;</b></td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntVoluntaryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntCompulsoryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntFinalTotal.ToString() + "</td>";
                _html += "</tr>";

                _html += "</table>";

                _html += "<table width='25%' cellpadding='1' cellspacing='1'>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "</table>";

                //Marketing
                _html += "<table width='20%' cellpadding='1' cellspacing='1' border='1'>";
                _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>" + Resources.NonGG.InternalMarketing + "</b></td></tr>";
                _html += "<tr>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Insurer + "</b></td>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Voluntary + "</b></td>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Compulsory + "</b></td>";
                _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>" + Resources.NonGG.Total + "</b></td>";
                _html += "</tr>";

                for (int d = 0; d < 10; d++)
                {
                    _html += "<tr>";
                    _html += "<td align='center'><b>" + MktInsurer[d].ToString() + "</b></td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktVoluntary[d].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktCompulsory[d].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktTotal[d].ToString() + "</td>";
                    _html += "</tr>";
                }

                _html += "<tr>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100;'><b>&nbsp;</b></td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktVoluntaryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktCompulsoryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktFinalTotal.ToString() + "</td>";
                _html += "</tr>";

                _html += "</table>";
                _html += "</body>";
                _html += "</html>";
                #endregion

                lblContent.Text = _html;
                ExportGridView(_fileName, lblContent);
            }
        }
        else
        {
        }
    }

    public string GetPaymentDetailList(Int64 CECarId, Int64 CXBrokerProviderId, string CollectedPremium)
    {
        int _CC = 0;
        int _CH = 0;
        int _BT = 0;
        string _PayDetails = " ";
        string _strVAT7 = "0";
        string _strBBLCharge = "0";
        string _strBBLNetReceived = "0";
        string _paymentDate = " ";
        float fl_CollectedPremium = Convert.ToSingle(CollectedPremium);
        MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMBrokerPremiumSelectSingleItem";
        _sPara.Add("@CXBrokerProviderId", CXBrokerProviderId);
        _sPara.Add("@CECarId", CECarId);
        _sPara.Add("@SelectedStatus", true);
        DataSet _dsPayment = new DataSet();
        DataTable _dtPayment = new DataTable();
        _dsPayment = _db.GetDataSet(_spName, _sPara);
        if (_dsPayment != null && _dsPayment.Tables.Count > 1 && _dsPayment.Tables[1].Rows.Count > 0)
        {
            _dtPayment = _dsPayment.Tables[1];
            _paymentDate = _dtPayment.Rows[0]["ModifiedDate"].ToString();
            for (int i = 0; i < _dtPayment.Rows.Count; i++)
            {
                string _paymentType = _dtPayment.Rows[i]["PaymentTypeID"].ToString().ToLower();
                if (_paymentType == "cash")
                {
                    _CH += 1;
                }
                else if (_paymentType == "bktr")
                {
                    _BT += 1;
                }
                else if (_paymentType == "ccip" || _paymentType == "ccol")
                {
                    _CC += 1;
                }
            }

            if (_CH > 0)
            {
                _PayDetails += "CASH";
            }

            if (_BT > 0)
            {
                if (_PayDetails.Trim() != string.Empty)
                {
                    _PayDetails += ",";
                }

                _PayDetails += "BKTR";
            }

            if (_CC > 0)
            {
                if (_PayDetails.Trim() != string.Empty)
                {
                    _PayDetails += ",";
                }

                _PayDetails += "CC";
            }
            if (_CC > 0)
            {
                _strBBLCharge = (fl_CollectedPremium * 0.03).ToString();
                _strBBLCharge = Math.Round(Convert.ToSingle(_strBBLCharge), 2).ToString();
                _strVAT7 = Math.Round((Convert.ToSingle(_strBBLCharge) * 0.07), 2).ToString();
            }
        }
        _strBBLNetReceived = Math.Round((Convert.ToSingle(fl_CollectedPremium) - Convert.ToSingle(_strBBLCharge) - Convert.ToSingle(_strVAT7)), 2).ToString();
        _PayDetails = _PayDetails + "@" + _paymentDate + "@" + _strBBLCharge + "@" + _strVAT7 + "@" + _strBBLNetReceived;
        return _PayDetails;
    }

    private string GetProvider(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "AZCP";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "MSIG";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "AXA";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "LMG";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "CTS";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "BKI";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "MTI";
        }
        else if (ProviderCompanyId == 35)
        {
            _result = "KPI";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "KUR";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "TMS";
        }
        return _result;
    }

    public string GetRemarks(string QuoteRefNo, Int16 TransactionTypeId)
    {
        string Remarks = "";
        MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMNonGGTransactionSelectItemByQuoteRefNo";
        _sPara.Add("@QuoteRefNo", QuoteRefNo);
        _sPara.Add("@TransactionTypeId", TransactionTypeId);
        DataSet _dsRemarks = new DataSet();
        _dsRemarks = _db.GetDataSet(_spName, _sPara);
        if (_dsRemarks != null && _dsRemarks.Tables.Count > 0 && _dsRemarks.Tables[0].Rows.Count > 0)
        {
            Remarks = _dsRemarks.Tables[0].Rows[0]["Remarks"].ToString();
        }
        return Remarks;
    }

    public DataTable GetPercentage(Int64 ProviderCompanyId, string PremiumType, Int64 InsuranceType, Int16 GarageType, string ReportDate)
    {
        MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMOICPercentageSelectSingleItem";
        _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
        _sPara.Add("@PremiumType", PremiumType);
        _sPara.Add("@InsuranceType", InsuranceType);
        _sPara.Add("@GarageType", GarageType);
        _sPara.Add("@ReportDate", ReportDate);
        DataTable _dtPercentage = new DataTable();
        _dtPercentage = _db.GetDataTableBySP(_spName, _sPara);
        return _dtPercentage;
    }

}
